﻿using System.Collections.Generic;
using System.Linq;

namespace TinyCms.Core.ExtendMethod
{
    /// <summary>
    /// 对IEnumberable接口的方法扩展
    /// </summary>
    public static class IEnumerable
    {
        /// <summary>
        /// 返回分页数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static IEnumerable<T> ToPageList<T>(this IEnumerable<T> source, int pageindex, int pagesize, out int count)
        {
            if (source == null)
            {
                count = 0;
                return null;
            }
            count = source.Count();
            return source.Skip((pageindex - 1) * pagesize).Take(pagesize);
        }
    }
}
